﻿

namespace Mulala.Cavan.Presentation.Mvc.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Domain.MainBoundedContext.NannyModule;
    using Mulala.Cavan.Presentation.Seedwork;
    using Spring.Context;
    using Spring.Context.Support;
    using Mulala.Cavan.Application.MainBoundedContext.AttachmentModule;
    using Mulala.Cavan.Application.MainBoundedContext.MulalaModule;

    public class NannyCommentViewModelConverter
    {
        public static IList<INannyCommentViewModel> Convert(IList<NannyComment> nannyComments)
        {
            IApplicationContext springContext = ContextRegistry.GetContext();
            IAttachmentAppService attachmentAppService = springContext.GetObject(MulalaAppServiceConst.ATTACHMENTAPPSERVICE) as IAttachmentAppService;

            IList<INannyCommentViewModel> nannyCommentViewModels = new List<INannyCommentViewModel>();
            if (null != nannyCommentViewModels)
            {
                foreach (NannyComment nannyComment in nannyComments)
                {
                    INannyCommentViewModel nannyCommentViewModel = ModelFactory.CreateModel<INannyCommentViewModel>();
                    nannyCommentViewModel.ProprietorID = nannyComment.Proprietor.ID;
                    nannyCommentViewModel.ProprietorName = nannyComment.Proprietor.Name;
                    nannyCommentViewModel.Avatar = attachmentAppService.GetProprietorAvatar(nannyComment.Proprietor);
                }
            }

            return nannyCommentViewModels;
        }
    }
}
